﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace UdpEchoServer
{
    class Program
    {
        static void Main(string[] args)
        {
            int port = 7;
            UdpClient client = null;

            try
            {
                client = new UdpClient(port);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);           
                Environment.Exit(1);
            }

            IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, port);

            try
            {
                byte[] buffer = client.Receive(ref endPoint);
                Console.Write("handling client on " + endPoint + " - ");
                client.Send(buffer, buffer.Length, endPoint);
                Console.WriteLine("echoed {0} bytes.", buffer.Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);                
            }
        }
    }
}
